package com.wanmait.meteor.controller;

import com.alibaba.fastjson.JSONObject;

import com.wanmait.meteor.pojo.Manager;
import com.wanmait.meteor.service.ManagerService;
import com.wanmait.meteor.util.IgnoreToken;
import com.wanmait.meteor.util.JWTUtils;
import com.wanmait.meteor.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@CrossOrigin
public class CommonController {

    @Resource
    private ManagerService managerService;

    @IgnoreToken
    @PostMapping("/manage/login")
    public Result login(@RequestBody Manager manager){
        Manager loginManager=managerService.login(manager);

        if(loginManager==null){
            return Result.error("登录失败，用户名或者密码错误");
        }
        //创建token
        String token = JWTUtils.createToken(loginManager);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("token",token);
        return Result.success(jsonObject);
    }

}
